import { fileURLToPath, URL } from 'node:url'
// import { visualizer } from 'rollup-plugin-visualizer'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  base: './', // 设置打包路径
  plugins: [
    vue(),
    /* visualizer({
      emitFile: false,
      file: 'stats.html',
      open: true
    }) */
    Components({
      resolvers: [
        AntDesignVueResolver({
          importStyle: false // css in js
        })
      ]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  build: {
    target: 'es2015', // 指定浏览器兼容性
    minify: 'terser', // 混淆器，terser构建后文件体积更小
    terserOptions: {
      compress: {
        drop_console: true, // 打包时删除console.log
        drop_debugger: true // 打包时删除debugger
      }
    }
  }
})
